package com.woniuxy.ptapp.app.util;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeQueryRequest;
import com.alipay.api.response.AlipayTradeQueryResponse;
import com.woniuxy.ptapp.common.config.AlipayConfig;

public class CheckOrderNumPayState {

    public static boolean check(String orderNum){
        AlipayTradeQueryRequest alipayRequest = new AlipayTradeQueryRequest();
        JSONObject bizContent = new JSONObject();
        bizContent.put("out_trade_no",orderNum);
        alipayRequest.setBizContent(bizContent.toString());
        //传入自定义alipayConfig参数
        AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
        AlipayTradeQueryResponse response =null;
        try {
             response = alipayClient.execute(alipayRequest);
            System.out.println(response.getTradeStatus());
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        String subMsg = response.getSubMsg();
        if(subMsg!=null){
            return false;
        }
        String tradeStatus = response.getTradeStatus();
        if(tradeStatus.equals("TRADE_SUCCESS")){
                return  true;
        }
        return false;
       }
}
